package homework;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
//作业3：
//在你生成的文件中，点名，奇数次点名的名字肯定是
//张三-男-23
public class Test12 {
	static File path = new File("D:\\FileTest\\name.txt");
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(path));
		String line="";
		ArrayList<String> textLine = new ArrayList<>();
		while((line=br.readLine())!=null){
			if(line.length()>0)textLine.add(line);
		}
		br.close();

		isZhangsan(textLine);
	}

	private static void isZhangsan(ArrayList<String> textLine) throws IOException {
		// TODO Auto-generated method stub
		FileWriter fw= new FileWriter(path);
		boolean flag = false;
		Random rd = new Random();
		String[] arr = textLine.get(0).split("-");
		
		if(Integer.parseInt(arr[3])%2==1) {
			System.out.println("奇数次");
			System.out.println("张三-男-23");
			for(String ls:textLine){
				if(!flag){
					fw.write(arr[0]+"-"+arr[1]+"-"+arr[2]+"-2");
					flag=true;
					fw.write("\n");
					continue;
				}
				fw.write(ls);
				fw.write("\n");
			}
			fw.close();
		}else {
			int rdName = rd.nextInt(100)+1;
			String[] nameArr = textLine.get(rdName).split("-");
			System.out.println("偶数次");
			System.out.println("随机到了第"+rdName+"号:"+nameArr[0]);
			for(String ls:textLine){
				if(!flag){
					fw.write(arr[0]+"-"+arr[1]+"-"+arr[2]+"-1");
					flag=true;
					fw.write("\n");
					continue;
				}
				fw.write(ls);
				fw.write("\n");
			}
			fw.close();
		}
	}
}
